package com.heihei.transvideo;

import com.heihei.config.ConfigProperties;
import com.heihei.util.FileUtilF;

import javax.swing.filechooser.FileSystemView;
import java.io.File;
import java.io.IOException;

/**
 *  用于抖音录屏转码  转mp4  2000k
 *
 * @author duanhengfei
 * 2022年06月27日 01:37:34
 */
public class TransVideo2Mp4 {
    public static void main(String[] args) throws IOException {
        start();
    }

    public static void start() throws IOException {
        System.out.println("请输入源文件夹：");
        File validSrcDir = FileUtilF.getValidSrcDir();
        System.out.println("请输入目标文件夹：");
        File validDesDir = FileUtilF.getValidDesDir();
        StringBuilder sb = new StringBuilder();
        for (File file : validSrcDir.listFiles()) {
            if(FileUtilF.isVideo(file)) {
                //组织命令
                //"C:/Develop/ffmpeg-n4.4-latest-win64-gpl-4.4/bin/ffmpeg" -i "古典舞小佩仪-爱江山更爱美人-2022-06-26 23_32.mp4" -c:v libx264 -b:v 2000k "古典舞小佩仪-爱江山更爱美人-2022-06-26 23_32_2000k.mp4"
                String targetFileName = file.getName();
                if(!file.getName().toLowerCase().endsWith(".mp4")) {
                    targetFileName = file.getName() + ".mp4";
                }
                String command = null;
                if(file.getName().endsWith("swf")) {
                    command = "\"" + ConfigProperties.FFMPEG_HOME_DIR + "\" -i \"" + file.getAbsolutePath() + "\" \"" + new File(validDesDir, targetFileName).getAbsolutePath() + "\"";
                } else {
                    command = "\"" + ConfigProperties.FFMPEG_HOME_DIR + "\" -i \"" + file.getAbsolutePath() + "\" -c:v libx264 -b:v 2000k \"" + new File(validDesDir, targetFileName).getAbsolutePath() + "\"";
                }
                System.out.println(command);
                sb.append(command).append("\r\n");
            }
        }
        sb.append("pause");
        FileSystemView fsv = FileSystemView.getFileSystemView();
        File com=fsv.getHomeDirectory();
        System.out.println(com.getPath()); //这便是桌面的具体路径
        FileUtilF.writeTxtFile(sb.toString(), new File(com, "target-trans-cmd.cmd"), "GBK");
    }
}
